package utils

import (
	"time"
)

type Run func()

func ScheduleAtFixedRate(f Run, initialDelay, period int64, duration time.Duration) {
	// 这里没有考虑进程退出的问题
	ticker := time.NewTicker(time.Duration(period) * duration)
	go func(ticker *time.Ticker) {
		time.Sleep(time.Duration(initialDelay) * duration)
		for {
			select {
			case <-ticker.C:
				f()
			}
		}
	}(ticker)
}
